create table [dbo].[Acaos] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
    [AtributoEnum] [int] not null,
    [CampoEnum] [int] not null,
    [SinalModificador] [bit] not null,
    [Modificador] [int] not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    [DisciplinaId] [bigint] null,
    [Discriminator] [nvarchar](128) not null,
    primary key ([Id])
);
create table [dbo].[Agrupamentoes] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[Armas] (
    [Id] [bigint] not null identity,
    [Dano] [int] not null,
    [Municao] [int] not null,
    [Custo] [int] not null,
    [Tamanho] [int] not null,
    [ForcaMinima] [int] not null,
    [Camara] [bit] not null,
    [AlcanceEnum] [int] not null,
    [TipoDanoEnum] [int] not null,
    [Observacao] [nvarchar](1000) null,
    [Inativado] [bit] not null,
	[Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[Clas] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
    [HerancaEnum] [int] not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[ClaDisciplinas] (
    [Id] [bigint] not null identity,
    [ClaId] [bigint] not null,
    [DisciplinaId] [bigint] not null,
    primary key ([Id])
);
create table [dbo].[Coalizaos] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
	[VantagemId] [bigint] not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[CoalizaoDisciplinas] (
    [Id] [bigint] not null identity,
    [CoalizaoId] [bigint] not null,
    [DisciplinaId] [bigint] not null,
    primary key ([Id])
);
create table [dbo].[CoalizaoVantagems] (
    [Id] [bigint] not null identity,
    [CoalizaoId] [bigint] not null,
    [VantagemId] [bigint] not null,
    primary key ([Id])
);
create table [dbo].[Cronicas] (
    [Id] [bigint] not null identity,
    [NarradorId] [bigint] not null,
    [Descricao] [nvarchar](1000) not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[Desvantagems] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[Devocaos] ( 
	[Id] [bigint] not null identity, 
	[Custo] [int] not null, 
	[Descricao] [nvarchar](1000) not null, 
	[Inativado] [bit] not null, 
	[Nome] [nvarchar](50) not null, 
	primary key ([Id])
	); 
create table [dbo].[DevocaoDisciplinas] ( 
	[Id] [bigint] not null identity, 
	[DevocaoId] [bigint] not null, 
	[DisciplinaId] [bigint] not null, 
	[Nivel] [int] not null, 
	primary key ([Id]) 
); 
create table [dbo].[Disciplinas] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
    [Privado] [bit] not null,
    [AgrupamentoId] [bigint] null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[EdmMetadata] (
    [Id] [int] not null identity,
    [ModelHash] [nvarchar](max) null,
    primary key ([Id])
);
create table [dbo].[Especializacaos] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
    [CampoEnum] [int] not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[Rituals] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
    [Nivel] [int] not null,
    [DisciplinaId] [bigint] not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[Humanoes] (
    [Id] [bigint] not null identity,
    [JogadorId] [bigint] not null,
    [CronicaId] [bigint] null,
    [VirtudeEnum] [int] not null,
    [VicioEnum] [int] not null,
    [TamanhoEnum] [int] not null,
    [Fator] [int] not null,
    [Experiencia] [int] not null,
    [Moralidade] [int] not null,
    [Vitalidade] [int] not null,
    [DanoContusao] [int] null,
    [DanoLetal] [int] null,
    [DanoAgravado] [int] null,
    [Energia] [int] not null,
    [Vontade] [int] not null,
    [VontadeTemporaria] [int] null,
    [PenalidadeEnum] [int] null,
    [Forca] [int] not null,
    [Destreza] [int] not null,
    [Vigor] [int] not null,
    [Presenca] [int] not null,
    [Manipulacao] [int] not null,
    [Autocontrole] [int] not null,
    [Inteligencia] [int] not null,
    [Raciocinio] [int] not null,
    [Perseveranca] [int] not null,
    [Armamento] [int] not null,
    [ArmasDeFogo] [int] not null,
    [Briga] [int] not null,
    [Conducao] [int] not null,
    [Dissimulacao] [int] not null,
    [Esportes] [int] not null,
    [Furto] [int] not null,
    [Sobrevivencia] [int] not null,
    [Astucia] [int] not null,
    [Empatia] [int] not null,
    [Expressao] [int] not null,
    [Intimidacao] [int] not null,
    [Manha] [int] not null,
    [Persuasao] [int] not null,
    [Socializacao] [int] not null,
    [TratoAnimais] [int] not null,
    [Ciencias] [int] not null,
    [Erudicao] [int] not null,
    [Informatica] [int] not null,
    [Investigacao] [int] not null,
    [Medicina] [int] not null,
    [Ocultismo] [int] not null,
    [Oficios] [int] not null,
    [Politica] [int] not null,
    [Nome] [nvarchar](50) not null,
	[Preferencial] [bit] null,
    [PenalidadeVontade] [int] null,
    [ClaId] [bigint] null,
    [CoalizaoId] [bigint] null,
    [Discriminator] [nvarchar](128) not null,
    primary key ([Id])
);
create table [dbo].[HumanoArmas] (
    [Id] [bigint] not null identity,
    [ArmaId] [bigint] not null,
    [HumanoId] [bigint] not null,
    primary key ([Id])
);
create table [dbo].[HumanoDesvantagems] (
    [Id] [bigint] not null identity,
    [HumanoId] [bigint] not null,
    [DesvantagemId] [bigint] not null,
    [TipoEnum] [int] not null,
    primary key ([Id])
);
create table [dbo].[HumanoEspecializacaos] (
    [Id] [bigint] not null identity,
    [EspecializacaoId] [bigint] not null,
    [HumanoId] [bigint] not null,
    primary key ([Id])
);
create table [dbo].[HumanoItems] (
    [Id] [bigint] not null identity,
    [ItemId] [bigint] not null,
    [HumanoId] [bigint] not null,
    primary key ([Id])
);
create table [dbo].[HumanoVantagems] (
    [Id] [bigint] not null identity,
    [VantagemId] [bigint] not null,
    [HumanoId] [bigint] not null,
    [Nivel] [int] not null,
    primary key ([Id])
);
create table [dbo].[Items] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[Usuarios] (
    [Id] [bigint] not null identity,
    [TipoEnum] [int] not null,
    [Login] [nvarchar](20) not null,
    [Senha] [nvarchar](40) not null,
    [Email] [nvarchar](40) not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[VampiroDevocaos] ( 
	[Id] [bigint] not null identity, 
	[VampiroId] [bigint] not null, 
	[DevocaoId] [bigint] not null, 
	primary key ([Id]) 
); 
create table [dbo].[VampiroDisciplinas] (
    [Id] [bigint] not null identity,
    [VampiroId] [bigint] not null,
    [DisciplinaId] [bigint] not null,
    [Nivel] [int] not null,
	primary key ([Id])
);
create table [dbo].[VampiroRituals] (
    [Id] [bigint] not null identity,
    [VampiroId] [bigint] not null,
    [RitualId] [bigint] not null,
    primary key ([Id])
);
create table [dbo].[Vantagems] (
    [Id] [bigint] not null identity,
    [Descricao] [nvarchar](1000) not null,
    [DisponivelNaCriacao] [bit] not null,
    [UsadoPorHumano] [bit] not null,
    [UsadoPorVampiro] [bit] not null,
    [Inativado] [bit] not null,
    [Nome] [nvarchar](50) not null,
    primary key ([Id])
);
create table [dbo].[VantagemCampoes] (
    [Id] [bigint] not null identity,
    [CampoEnum] [int] not null,
    [VantagemId] [bigint] not null,
    [Valor] [int] not null,
    primary key ([Id])
);
create table [dbo].[VantagemNivels] (
    [Id] [bigint] not null identity,
    [Nivel] [int] not null,
    [Descricao] [nvarchar](1000) not null,
    [VantagemId] [bigint] not null,
    [Nome] [nvarchar](50) null,
    primary key ([Id])
);
alter table [dbo].[Acaos] add constraint [AcaoDisciplina_Disciplina] foreign key ([DisciplinaId]) references [dbo].[Disciplinas]([Id]);
alter table [dbo].[ClaDisciplinas] add constraint [ClaDisciplina_Cla] foreign key ([ClaId]) references [dbo].[Clas]([Id]) on delete cascade;
alter table [dbo].[ClaDisciplinas] add constraint [ClaDisciplina_Disciplina] foreign key ([DisciplinaId]) references [dbo].[Disciplinas]([Id]) on delete cascade;
alter table [dbo].[Coalizaos] add constraint [Coalizao_Vantagem] foreign key ([VantagemId]) references [dbo].[Vantagems]([Id]) on delete no action;
alter table [dbo].[CoalizaoDisciplinas] add constraint [CoalizaoDisciplina_Coalizao] foreign key ([CoalizaoId]) references [dbo].[Coalizaos]([Id]) on delete cascade;
alter table [dbo].[CoalizaoDisciplinas] add constraint [CoalizaoDisciplina_Disciplina] foreign key ([DisciplinaId]) references [dbo].[Disciplinas]([Id]) on delete cascade;
alter table [dbo].[CoalizaoVantagems] add constraint [CoalizaoVantagem_Coalizao] foreign key ([CoalizaoId]) references [dbo].[Coalizaos]([Id]) on delete cascade;
alter table [dbo].[CoalizaoVantagems] add constraint [CoalizaoVantagem_Vantagem] foreign key ([VantagemId]) references [dbo].[Vantagems]([Id]) on delete cascade;
alter table [dbo].[Cronicas] add constraint [Cronica_Narrador] foreign key ([NarradorId]) references [dbo].[Usuarios]([Id]) on delete cascade;
alter table [dbo].[DevocaoDisciplinas] add constraint [DevocaoDisciplina_Devocao] foreign key ([DevocaoId]) references [dbo].[Devocaos]([Id]) on delete cascade; 
alter table [dbo].[DevocaoDisciplinas] add constraint [DevocaoDisciplina_Disciplina] foreign key ([DisciplinaId]) references [dbo].[Disciplinas]([Id]) on delete cascade; 
alter table [dbo].[Disciplinas] add constraint [Disciplina_Agrupamento] foreign key ([AgrupamentoId]) references [dbo].[Agrupamentoes]([Id]) on delete cascade;
alter table [dbo].[Humanoes] add constraint [Humano_Cronica] foreign key ([CronicaId]) references [dbo].[Cronicas]([Id]) on delete no action;
alter table [dbo].[Humanoes] add constraint [Humano_Jogador] foreign key ([JogadorId]) references [dbo].[Usuarios]([Id]) on delete cascade;
alter table [dbo].[HumanoArmas] add constraint [HumanoArma_Arma] foreign key ([ArmaId]) references [dbo].[Armas]([Id]) on delete cascade;
alter table [dbo].[HumanoArmas] add constraint [HumanoArma_Humano] foreign key ([HumanoId]) references [dbo].[Humanoes]([Id]) on delete cascade;
alter table [dbo].[HumanoDesvantagems] add constraint [HumanoDesvantagem_Desvantagem] foreign key ([DesvantagemId]) references [dbo].[Desvantagems]([Id]) on delete cascade;
alter table [dbo].[HumanoDesvantagems] add constraint [HumanoDesvantagem_Humano] foreign key ([HumanoId]) references [dbo].[Humanoes]([Id]) on delete cascade;
alter table [dbo].[HumanoEspecializacaos] add constraint [HumanoEspecializacao_Especializacao] foreign key ([EspecializacaoId]) references [dbo].[Especializacaos]([Id]) on delete cascade;
alter table [dbo].[HumanoEspecializacaos] add constraint [HumanoEspecializacao_Humano] foreign key ([HumanoId]) references [dbo].[Humanoes]([Id]) on delete cascade;
alter table [dbo].[HumanoItems] add constraint [HumanoItem_Humano] foreign key ([HumanoId]) references [dbo].[Humanoes]([Id]) on delete cascade;
alter table [dbo].[HumanoItems] add constraint [HumanoItem_Item] foreign key ([ItemId]) references [dbo].[Items]([Id]) on delete cascade;
alter table [dbo].[HumanoVantagems] add constraint [HumanoVantagem_Humano] foreign key ([HumanoId]) references [dbo].[Humanoes]([Id]) on delete cascade;
alter table [dbo].[HumanoVantagems] add constraint [HumanoVantagem_Vantagem] foreign key ([VantagemId]) references [dbo].[Vantagems]([Id]) on delete cascade;
alter table [dbo].[Rituals] add constraint [Ritual_Disciplina] foreign key ([DisciplinaId]) references [dbo].[Disciplinas]([Id]);
alter table [dbo].[Humanoes] add constraint [Vampiro_Cla] foreign key ([ClaId]) references [dbo].[Clas]([Id]) on delete cascade;
alter table [dbo].[Humanoes] add constraint [Vampiro_Coalizao] foreign key ([CoalizaoId]) references [dbo].[Coalizaos]([Id]) on delete cascade;
alter table [dbo].[VampiroDevocaos] add constraint [VampiroDevocao_Devocao] foreign key ([DevocaoId]) references [dbo].[Devocaos]([Id]) on delete cascade; 
alter table [dbo].[VampiroDevocaos] add constraint [VampiroDevocao_Vampiro] foreign key ([VampiroId]) references [dbo].[Humanoes]([Id]) on delete cascade; 
alter table [dbo].[VampiroDisciplinas] add constraint [VampiroDisciplina_Disciplina] foreign key ([DisciplinaId]) references [dbo].[Disciplinas]([Id]) on delete cascade;
alter table [dbo].[VampiroDisciplinas] add constraint [VampiroDisciplina_Vampiro] foreign key ([VampiroId]) references [dbo].[Humanoes]([Id]) on delete cascade;
alter table [dbo].[VampiroRituals] add constraint [VampiroRitual_Ritual] foreign key ([RitualId]) references [dbo].[Rituals]([Id]) on delete cascade;
alter table [dbo].[VampiroRituals] add constraint [VampiroRitual_Vampiro] foreign key ([VampiroId]) references [dbo].[Humanoes]([Id]) on delete cascade;
alter table [dbo].[VantagemCampoes] add constraint [VantagemCampo_Vantagem] foreign key ([VantagemId]) references [dbo].[Vantagems]([Id]) on delete cascade;
alter table [dbo].[VantagemNivels] add constraint [VantagemNivel_Vantagem] foreign key ([VantagemId]) references [dbo].[Vantagems]([Id]) on delete cascade;

alter table [dbo].[Acaos] add constraint [UK_Acaos_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Agrupamentoes] add constraint [UK_Agrupamentoes_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Armas] add constraint [UK_Armas_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Clas] add constraint [UK_Clas_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[ClaDisciplinas] add constraint [UK_ClaDisciplinas_ClaId_DisciplinaId] unique nonclustered([ClaId], [DisciplinaId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Coalizaos] add constraint [UK_Coalizaos_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[CoalizaoDisciplinas] add constraint [UK_CoalizaoDisciplinas_CoalizaoId_DisciplinaId] unique nonclustered([CoalizaoId], [DisciplinaId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[CoalizaoVantagems] add constraint [UK_CoalizaoVantagems_CoalizaoId_VantagemId] unique nonclustered([CoalizaoId], [VantagemId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Cronicas] add constraint [UK_Cronicas_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Desvantagems] add constraint [UK_Desvantagems_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Devocaos] add constraint [UK_Devocaos_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[DevocaoDisciplinas] add constraint [UK_DevocaoDisciplinas_DevocaoId_DisciplinaId] unique nonclustered([DevocaoId], [DisciplinaId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Disciplinas] add constraint [UK_Disciplinas_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Especializacaos] add constraint [UK_Especializacaos_Campo_Nome] unique nonclustered([CampoEnum], [Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Humanoes] add constraint [UK_Humanoes_Nome_CronicaId] unique nonclustered([Nome], [CronicaId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[HumanoDesvantagems] add constraint [UK_HumanoDesvantagems_HumanoId_DesvantagemId] unique nonclustered([HumanoId], [DesvantagemId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[HumanoEspecializacaos] add constraint [UK_HumanoEspecializacaos_HumanoId_EspecializacaoId] unique nonclustered([HumanoId], [EspecializacaoId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[HumanoVantagems] add constraint [UK_HumanoVantagems_HumanoId_VantagemId] unique nonclustered([HumanoId], [VantagemId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Items] add constraint [UK_Items_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Rituals] add constraint [UK_Rituals_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Usuarios] add constraint [UK_Usuarios_Login] unique nonclustered([Login]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[VampiroDevocaos] add constraint [UK_VampiroDevocaos_VampiroId_DevocaoId] unique nonclustered([VampiroId], [DevocaoId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[VampiroDisciplinas] add constraint [UK_VampiroDisciplinas_VampiroId_DisciplinaId] unique nonclustered([VampiroId], [DisciplinaId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[VampiroRituals] add constraint [UK_VampiroRituals_VampiroId_RitualId] unique nonclustered([VampiroId], [RitualId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[Vantagems] add constraint [UK_Vantagems_Nome] unique nonclustered([Nome]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[VantagemCampoes] add constraint [UK_VantagemCampoes_Campo_VantagemId] unique nonclustered([CampoEnum], [VantagemId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];
alter table [dbo].[VantagemNivels] add constraint [UK_VantagemNivels_Nivel_VantagemId] unique nonclustered([Nivel], [VantagemId]) with(statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary];